<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="model.Collecte" %>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Clean-Nantes - infos sur la collecte des déchets de Nantes</title>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, maximum-scale=1, minimum-scale=1">
<link rel="stylesheet" type="text/css" href="css/default.css" media="all">
<link rel="stylesheet" type="text/css" href="css/flexslider.css">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=PT+Sans">
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.flexslider.js"></script>
<script src="js/default.js"></script>
<!--[if lt IE 9]>
<script src="js/html5.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="pagewidth">
    <a href="/clean_nantes"><img style="float:left;" src="img/nantes.png" alt="" width="200px"/><img src="img/accueil.png" title="Accueil" width="32" style="float:left;margin-top:52px;"/></a>
    <%
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
	%>
	<a href='<%= userService.createLogoutURL(request.getRequestURI()) %>'><img style="float:right;margin:10px 10px 0px 0px;" onMouseOver="this.src='img/google_deco_hover.png'" onMouseOut="this.src='img/google_deco.png'" src="img/google_deco.png" alt=""/></a>
	<span style="color:white;float:right;margin:18px -190px 0px 0px;">Déconnexion</span>
    <p style="float:right;color:white;margin:47px -190px 0px 0px;">Bienvenue, <%= user.getNickname() %> !</p>
  	<%
    } else {
	%>
	 <a href='<%= userService.createLoginURL("/clean_nantes") %>'><img style="float:right;margin:10px 10px 0px 0px;" onMouseOver="this.src='img/google_hover.png'" onMouseOut="this.src='img/google.png'" src="img/google.png" alt=""/></a>
	<%
    }
	%>
  <div id="content">
    <section id="contactUs" class="row grey">
      <div class="center">
        
        <strong class="subHeading">Toutes les informations sur la collecte des déchets dans votre ville !</strong>
        <div class="columns">
            <form action="clean_nantes" method="get" class="form">
              <fieldset>
                <h2>Les jours de collecte chez vous...</h2>
                
                <div class="formRow">
                <%
                if(request.getAttribute("addrSaved")!=null){
        	        String addr_saved = (String) request.getAttribute("addrSaved");
                %>
                	<p><img src="img/pin.png" alt="" width="28" style="float:left;" title="Adresse enregistrée" /><br /><strong>&nbsp;Localisation enregistrée : </strong><i><% out.println(addr_saved); %></i><a href="/delete"><img src="img/delete.png" width="18" style="right" title="Supprimer"/></a></p>
                <% } %>
                  <div class="textField">
                    <input type="text" name="recherche" placeholder="Saisissez votre adresse ...">
                  </div>
                </div>
                <div class="formRow">
                  <button class="btnSmall btn submit"> <span>GO !</span> </button>
                </div>
              </fieldset>
            </form>
            
          <%
          if(request.getAttribute("infos")!=null){
			ArrayList<Collecte> infos = new ArrayList<Collecte>(); 
	        infos = (ArrayList<Collecte>) request.getAttribute("infos");
	        %>
            <h2><% out.println(infos.size());%> résultat(s) : </h2>
            <div id="map">
            <table style="border:0;">
	        	<tr>
	        	<td width="200px" style="text-align:center;"><img src="img/home.png" width="32" alt="" /></td>
	        	<td width="200px" style="text-align:center;"><img src="img/infos.png" width="32" alt="" /></td>
	        		<td width="150px" style="text-align:center;">
	        			<img src="img/garbage_jaune.png" width="32" alt="" />
	        		</td>
	        		<td width="150px" style="text-align:center;">
	        			<img src="img/garbage_bleu.png" width="32" alt="" />
	        		</td>
	        		<td width="150px" style="text-align:center;">
	        			<img src=img/trisac.png height="34px" alt="" />
	        		</td>
	        		<td></td>
	        	</tr>
	        <% 
	        int bool = 0 ;
	        for (int i =0; i<infos.size();i++) { 
	        	if(infos.get(i).getProvenance()=="Libelle"){ 
	        	bool = 1 ;
	        	%>
	        	<tr style="border-bottom: 1px solid #333333;">
	        		<td style="text-align:center;">
	        		<%
	        				out.println(infos.get(i).getLibelle());
	        		%>
	        		</td>
	        		<td style="text-align:center;">
	        		<%
	        				out.println(infos.get(i).getObs_prestation_collecte());
	        		%>
	        		</td>
	        		
	        		<td style="text-align:center;">
	        		<% if(!infos.get(i).getPrestation_collecte().toUpperCase().contains("TRI'SAC")) out.println(infos.get(i).getJaune_jour_collecte()); %>
	        		</td>
	        		
	        		<td style="text-align:center;">
	        		<% if(!infos.get(i).getPrestation_collecte().toUpperCase().contains("TRI'SAC")) out.println(infos.get(i).getBleu_jour_collecte());%>
	        		</td>
	        		<td style="text-align:center;">
	        			<% if(infos.get(i).getPrestation_collecte().toUpperCase().contains("TRI'SAC"))  out.println(infos.get(i).getBleu_jour_collecte());%>
	        		</td>
	        		<td>
	        			<form class="mail" action="save_collecte" method="get">
	        				<input type="submit" value="" />
	        				<input type="hidden" name="adresse" value="<% out.print(infos.get(i).getLibelle()) ;%>" />
	        				<input type="hidden" name="user_mail" value="<% out.print(user.getEmail()); %>" />
	        				<% if(infos.get(i).getPrestation_collecte().toUpperCase().contains("TRI'SAC")){ %>
	        					<input type="hidden" name="trisac" value="<% out.print(infos.get(i).getBleu_jour_collecte()); %>" />
	        				<% }else{ %>
	        					<input type="hidden" name="jaune" value="<% out.print(infos.get(i).getJaune_jour_collecte()); %>" />
	        					<input type="hidden" name="bleu" value="<% out.print(infos.get(i).getBleu_jour_collecte()); %>" />
	        				<% } %>
	        			</form>
	        		</td>
	        	</tr>
	        <% }
	        } 
	        for(int i=0; i<infos.size(); i++){ 
	        	if(bool==0 && infos.get(i).getProvenance()=="Tenant"){
	        	%>
	        	<tr style="border-bottom: 1px solid #333333;">
	        		<td style="text-align:center;">
	        		<%
	        				out.println(infos.get(i).getTenant());	
	        		%>
	        		</td>
	        		
	        		<td style="text-align:center;">
	        		<% out.println(infos.get(i).getJaune_jour_collecte()); %>
	        		</td>
	        		
	        		<td style="text-align:center;">
	        		<% out.println(infos.get(i).getBleu_jour_collecte()); %>
	        		</td>
	        		<td style="text-align:center;">
	        			<a href="#">+ d'infos</a>
	        		</td>
	        	</tr>
	        <% }
	        } %>
	        </table>
	        </div>
          <% }%>
      </div>
      </div>
    </section>
  </div>
  <footer id="footer">
    <div class="center"><span class="copy"><a href="user_documentation.jsp">Comment utiliser l'application ?</a></span></div>
  </footer>
</div>
</body>
</html>
